{%include file="header.html"%}
<style>
td {	font-weight: bold;}
.input {	width: 200px;}
textarea {	width: 350px;	height: 100px;}
select {	width: 150px;}
.active_body {	display: none;	min-height: 500px;}
.active_nav {	font-weight: bold;	background: #8AD7D7;}
.fixed-nav ul li {	cursor: pointer;}
.tishi{color:#999;margin-top:5px;}
</style>
<body>
<div class="fixed-bar">
  <div class="item-title">
    <h3>编辑商品</h3>
  </div>
  <div class="fixed-nav">
    <ul>
      <li class="active_nav">通用信息</li>
      <li>详细描述</li>
      <li>其他信息</li>
      <li>商品属性</li>
      <li>商品相册</li>
    </ul>
  </div>
</div>
<div class="fixed_bottom" style="margin-top:92px;">
  <form method="post" action="goods.php" id="aspnetForm" name="form1" enctype="multipart/form-data" onsubmit="return check()">
    <div class="active_body" style="display:block;">
      <table style=" width:100%;" cellpadding="0" cellspacing="0" class="table tb-type2">
        <tr>
          <td class="firtd"> 商品名称:</td>
          <td>
              <input type="text" class="input" name="goods_name" required value="{%$edit.goods_name%}"> *
              <input type="hidden" name="act" value="edit">
              <input type="hidden" name="goods_id" value="{%$edit.goods_id%}">
          </td>
        </tr>
        <tr>
          <td class="firtd"> 商铺:</td>
          <td>
          	{%if $edit.user_id%}
            	<a>{%$goods_usershid.shop_name%}</a>
              <input type="hidden" name="user_id" value="{%$goods_usershid.s_id%}">
            {%else%}
                <select onChange="quyush(this,'user_id')" required>
                    <option value="">=请选择=</option>
                    {%foreach from=$shop_region item=ranksshop%}
                    <option value="{%$ranksshop.r_id%}">{%$ranksshop.r_name%}</option>
                    {%/foreach%}
                </select>
                <select name="user_id">
                <option value="0">请选择</option>
                    {%foreach from=$shop_list item=shop%}
                    <option {%if $goods.user_id==$shop.s_id%}selected="selected"{%/if%} value="{%$shop.s_id%}">{%$shop.shop_name%}</option>
                    {%/foreach%}
                </select>
            {%/if%}
          </td>
        </tr>
        <tr>
          <td class="firtd"> 商品货号 :</td>
          <td><input type="text" class="input" name="goods_sn" required value="{%$edit.goods_sn%}"> *</td>
        </tr>
        <tr>
          <td class="firtd"> 商品分类:</td>
          <td><select name="cat_id" id="" required>
              <option value='' id="option">请选择...</option>
              {%$type%}
            </select></td>
        </tr>
        <tr>
          <td class="firtd"> 商品品牌:</td>
          <td>
            <select name="brand_id" id="" required>
              <option value='' id="option">请选择...</option>
              {%foreach from=$brand item=brands%}
                <option {%if $edit.brand_id == $brands.brand_id%} selected="selected"  {%/if%} required value="{%$brands.brand_id%}">{%$brands.brand_name%}</option>
              {%/foreach%}
            </select>
          </td>
        </tr>
        <tr>
          <td class="firtd"> 本店售价 :</td>
          <td><input onkeyup="value=value.replace(/[^\d.]/g,'')" type="text" class="input" name="shop_price" required value="{%$edit.shop_price%}"> *</td>
        </tr>
        <tr style="display:none;">
          <td class="firtd"> 会员价格 :</td>
          <td> 
            {%foreach from=$rank item=ranks%}
               {%$ranks.rank_name%}&nbsp;&nbsp;<input class="input" type="text" name="ad_name" required value="{%$list.ad_name%}">*
            {%/foreach%}
          </td>
        </tr>
        <tr>
          <td class="firtd"> 市场售价 :</td>
          <td><input onkeyup="value=value.replace(/[^\d.]/g,'')" type="text" class="input" name="market_price" required value="{%$edit.market_price%}"> *</td>
        </tr>
        <tr>
          <td class="firtd"> 上传商品图片:</td>
          <td>
              <span class="type-file-box">
                <input style="height:20px;" value="{%$edit.img_name%}" id="goodsImg" class="type-file-text" type="text">
                <input name="button" value="" class="type-file-button" type="button">
                <input class="type-file-file" onChange="get_imgval(this)" type="file" name="goods_img">
              </span>
              {%if $edit.goods_img%}<a target="_blank" style="margin-left:15px;" href="../{%$edit.goods_img%}"><img height="30" src="../{%$edit.goods_img%}"/></a>{%/if%}
              <p style=" margin-top:-8px;" class="tishi">（建议上传 900*900 的高清大图）</p>
          </td>
        </tr>
      </table>
      
    </div>
    <div class="active_body">
      <table style=" width:100%;" cellpadding="0" cellspacing="0" class="table tb-type2">
        <tr>
          <td class="firtd"> 详细描述:</td>
          <td>
		  	<script type="text/javascript" src="{%$URL%}resource/kindeditor/kindeditor.js"></script>
            <textarea style="width:1200px; height:600px;" name="goods_desc" id="goods_desc">{%$edit.goods_desc%}</textarea>
            <script>
              KindEditor.ready(function(K) {
                var editor1 = K.create('textarea[name="goods_desc"]', {
                  allowFileManager : true,
                  filterMode : false,
                  afterBlur:function(){ 
                    this.sync(); 
                  }
                });
              });
            </script>
          </td>
        </tr>
      </table>
    </div>
    <div class="active_body">
      <table style=" width:100%;" cellpadding="0" cellspacing="0" class="table tb-type2">
        <tr>
          <td class="firtd"> 商品重量:</td>
          <td><input class="input" type="text" name="goods_weight" required value="{%$edit.goods_weight%}"> *</td>
        </tr>
        <tr>
          <td class="firtd"> 商品库存数量:</td>
          <td><input class="input" type="text" name="goods_number" required value="{%$edit.goods_number%}">  *</td>
        </tr>
        <tr>
          <td class="firtd"> 库存警告数量:</td>
          <td><input class="input" type="text" name="warn_number" required value="{%$edit.warn_number%}">  *</td>
        </tr>
        <tr>
          <td class="firtd"> 加入推荐:</td>
          <td>
              {%foreach from=$sx item=sxs%}   
          	     <input type="checkbox" {%if strstr($edit.is_best,","|cat:$sxs.id|cat:",")%} checked{%/if%} name="is_best[]" value="{%$sxs.id%}"/>{%$sxs.name%}
              {%/foreach%}
          </td>
        </tr>
        <tr>
          <td class="firtd"> 上架:</td>
          <td><input type="checkbox" name="is_on_sale" class="upper" {%if $edit.is_on_sale == 1%} checked="checked" value="1"{%else%} value="0" {%/if%} />打勾表示允许销售，否则不允许销售。</td>
        </tr>
        <tr>
          <td class="firtd"> 能作为普通商品销售:</td>
          <td><input type="checkbox" name="is_alone_sale" class="upper" {%if $edit.is_alone_sale == 1%} checked="checked" value="1"{%else%} value="0" {%/if%}/>打勾表示能作为普通商品销售，否则只能作为配件或赠品销售。 </td>
        </tr>
<!--         <tr>
          <td class="firtd"> 是否为免运费商品:</td>
          <td><input type="checkbox" name="checkbox3" class="upper" {%if $edit.checkbox3 == 1%} checked="checked" value="1"{%else%} value="0" {%/if%}/>打勾表示此商品不会产生运费花销，否则按照正常运费计算。 </td>
        </tr> -->
        <tr>
          <td class="firtd"> 商品关键词：</td>
          <td>
              <input type="text" class="input" name="keywords" required value="{%$edit.keywords%}">
          </td>
        </tr>
        <tr>
          <td class="firtd"> 商品简单描述：</td>
          <td><textarea name="goods_brief" required style="min-height:120px; max-height:120px;">{%$edit.goods_brief%}</textarea></td>
        </tr>
        <tr>
          <td class="firtd"> 商家备注：</td>
          <td>
              <textarea name="seller_note" required style="min-height:120px; max-height:120px;">{%$edit.seller_note%}</textarea>
              <p class="tishi">仅供商家自己查看的信息</p>
          </td>
        </tr>
      </table>
    </div>
    <div class="active_body">
      <table style=" width:100%;" cellpadding="0" cellspacing="0" class="table tb-type2">
        <tr>
          <td class="firtd"> 商品类型:</td>
          <td>
          	<select name="goods_type" id="" onChange="getAttrList(this.value)">
            	<option required value="0">请选择商品类型</option>
                {%foreach from=$goods_type item=type_list%}
                <option {%if $type_list.cat_id == $edit.goods_type%} selected="selected" required {%/if%} value="{%$type_list.cat_id%}">{%$type_list.cat_name%}</option>
                {%/foreach%}
            </select></td>
        </tr>
        <tr>
        	<td id="tbody-goodsAttr" colspan="2">{%$goods_attr_html%}</td>
        </tr>
      </table>
    </div>
     <div class="active_body">
      <table id="img_desctab" style=" width:100%;" cellpadding="0" cellspacing="0" class="table tb-type2">
      	<tr>
        	<td colspan="2">
            	{%foreach from=$goods_imgs item=imgs_list%}
            	<div style=" width:110px; height:155px; float:left; margin-left:10px; padding:3px; border:1px solid #DADADA; margin-top:10px; text-align:center;">
                	  <a onClick="del_goods_imgs(this,{%$imgs_list.img_id%})" href="javascript:;">[-]</a><br />
                    <a href="../{%$imgs_list.img_original%}" target="_blank"><img src="../{%$imgs_list.thumb_url%}" width="110" height="110" /></a><br>
                    <input type="text" name="" value="{%$imgs_list.img_desc%}" onChange="update_goods_imgs(this,{%$imgs_list.img_id%})" style="width:90%; height:18px;" />
                </div>
                {%/foreach%}
            </td>
        </tr>
        <tr>
          <td class="firtd"><a onclick="addImg(this)" href="javascript:">[+]</a> 上传商品图片:</td>
          <td>
          	<span class="type-file-box">
                <input name="textfield[]" style="height:20px;" class="type-file-text" type="text">
                <input name="button" value="" class="type-file-button" type="button">
                <input class="type-file-file" id="acc" onChange="get_imgval(this)" type="file" name="file_url[]">
            </span>
            <span>&nbsp;&nbsp;图片描述：<input style="height:20px;" type="text" name="img_desc[]" /></span>
            <span>&nbsp;&nbsp;或外部图片链接：<input style="height:20px; width:200px;" onblur="abc(this)" type="text" name="img_url[]" placeholder="或者输入外部图片链接地址" /></span>
          </td>
        </tr>
      </table>
    </div> 
    <div style="text-align:center">
      <div class="style1">&nbsp;</div>
      <div> <a href="JavaScript:void(0);" class="btn" onclick="reset()"><span>重置</span></a> <a href="JavaScript:void(0);" class="btn" onclick="$('#tj').click()"><span>确认提交</span></a> </div>
    </div>
    <input type="reset" id="cz" style="display: none;">
    <input type="submit" id="tj" style="display:none;";>
  </form>
</div>
</body>
<script>
// 重置方法
function reset(){
	$('input').val('');
	$('textarea').text('');
	$('select').val('');
}
//获取焦点的时候
function quyush(th,cla){
	var id=$(th).val();
	$.post("shop_ajax.php?act=qysh",{id:id},function(data){
		if(data){
			$("select[name="+cla+"]").html(data);
		}else{
			$("select[name="+cla+"]").html("<option value='0'>暂无</option>");
		}
		
	})
}
// 商品添加点击切换内容模块
$(".fixed-nav>ul>li").click(function(){ 
  $(this).addClass('active_nav').siblings().removeClass('active_nav');
  var index=$(this).index();
  $(".active_body").eq(index).show().siblings(".active_body").hide();
});
//点击切换上下架的value值
$(".upper").click(function(){
  val=$(this).val();
  if(val==1){
    $(this).attr("value","0");
  }else{
    $(this).attr("value","1");
  }
});
/*图片改变的时候获取元素内容*/
function get_imgval(obj){
	var str=$(obj).val();
	var arr=str.split('\\');//注split可以用字符或字符串分割 
	var con=arr[arr.length-1];//这就是要取得的图片名称 
	$(obj).siblings("input[type='text']").val(con);
  if(con){
      $(obj).parent().next().next("span").children("input").attr("disabled",true);
  }else{
      $(obj).parent().next().next("span").children("input").attr("disabled",false);
  }
  
}
/*点击+添加图片*/
function addImg(obj){
	var con=$(obj).parents("#img_desctab tr").html();
	var a='<a onclick="removeImg(this)" href="javascript:">[-]</a>';
	var ya='<a onclick="addImg(this)" href="javascript:">[+]</a>';
	con=con.replace(ya,a);
	con="<tr>"+con+"</tr>";
	$(obj).parents("#img_desctab").append(con);
}
/*点击-号取消图片*/
function removeImg(obj){ 
	$(obj).parents("#img_desctab tr").remove();
}
/*商品属性添加多条*/
function addSpec(obj){
	var con=$(obj).parents("#attrTable tr").html();
	var a='<a href="javascript:;" onclick="removeSpec(this)">[-]</a>';
	var ya='<a href="javascript:;" onclick="addSpec(this)">[+]</a>';
	con=con.replace(ya,a);
	con="<tr>"+con+"</tr>";
	$(obj).parents("#attrTable tr").after(con);
}
/*商品属性移除*/
function removeSpec(obj){
	$(obj).parents("#attrTable tr").remove();
}
/*修改属性获取对应内容*/
function getAttrList(cat_id){
	var goods_id="{%$edit.goods_id%}";
	$.post("goods.php?act=attr_ajax",{cat_id:cat_id,goods_id:goods_id},function(data){
		$("#tbody-goodsAttr").html(data);
	})
}
/*删除商品图库图片*/
function del_goods_imgs(obj,id){
	layer.confirm('您确实要删除该图片吗？', {
		btn: ['确定','取消'] //按钮
	}, function(){
		$.post("goods.php?act=edit_imgs",{id:id,zt:"del"},function(data){
			if(data==1){
        $(obj).parent().remove();
				layer.msg('删除成功！', {icon: 1});
			}else{
				layer.msg('请求失败！', {icon: 2});
			}
		})
	}, function(){
		layer.msg('已取消！', {icon: 1});
	});
}
/*ajax修改图库图片的说明*/
function update_goods_imgs(obj,id){
  var val=$(obj).val();
	$.post("goods.php?act=edit_imgs",{id:id,zt:"update",vals:val},function(data){
		if(data==1){
			layer.msg('已修改！', {icon: 1});
		}else{
			layer.msg('请求失败！', {icon: 2});
		}
	})
}
//from表单提交验证
function check(){
      if(($("#goodsImg").val())==''){
         layer.msg('请添加上传商品图片！', {icon: 7});
         return false;
      }else{
         return true; 
      }
}
//当选择上传图片禁止输入远程链接
function abc(obj){
  var val=$(obj).val();
  if(val){
      $(obj).parent().prev().prev().children("#acc").attr("disabled",true);
  }else{
      $(obj).parent().prev().prev().children("#acc").attr("disabled",false);
  }
}
</script>
</html>